/**
 * 
 */
package com.thinkgsp.jxc.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 收款付款单
 * @author evan
 *
 */
public abstract class RpBill extends BaseModel implements RpBillCheck, Serializable {

	private static final long serialVersionUID = 6363673378873906377L;

	private Long rpBillId;
	private String rpBillCode;
	private Integer rpBillType;
	private String rpBillName;
	private Date billDate = new Date(System.currentTimeMillis());
	private Date funcDate = new Date(System.currentTimeMillis());
	private Integer direct;
	private Integer custSuppId;
	private Integer deptId;
	private Integer empId;
	private Integer makerId;
	private BigDecimal amount = BigDecimal.ZERO;
	private BigDecimal discount = BigDecimal.ZERO;
	private BigDecimal checkAmount = BigDecimal.ZERO;
	private Integer checkStatus = 0;
	private Integer fyear;
	private Integer period;
	private Boolean archived = false;
	private String remark;
	
	private BigDecimal currentCheckAmount = BigDecimal.ZERO;
	private Customer customer;
	private Dept dept;
	private Emp emp;
	private Emp maker;
	private List<RpBillDetail> details = new ArrayList<RpBillDetail>();
	
	public List<RpBillDetail> getDetails() {
		return details;
	}

	public void setDetails(List<RpBillDetail> details) {
		this.details = details;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
		if(customer != null) {
			this.custSuppId = customer.getCustomerId();
		}
	}

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
		if(dept != null) {
			this.deptId = dept.getDeptId();
		}
	}

	public Emp getEmp() {
		return emp;
	}

	public void setEmp(Emp emp) {
		this.emp = emp;
		if(emp != null) {
			this.empId = emp.getEmpId();
		}
	}

	public Emp getMaker() {
		return maker;
	}

	public void setMaker(Emp maker) {
		this.maker = maker;
		if(maker != null) {
			this.makerId = maker.getEmpId();
		}
	}

	public BigDecimal getBillAmount() {
		return amount.add(this.discount);
	}
	public BigDecimal getCheckedAmount() {
		return checkAmount;
	}
	public BigDecimal getCurrentCheckAmount() {
		return currentCheckAmount;
	}
	public void setCurrentCheckAmount(BigDecimal currentCheckAmount) {
		this.currentCheckAmount = currentCheckAmount;
	}
	/**
	 * 单据ID
	 * @return
	 */
	public Long getRpBillId() {
		return rpBillId;
	}

	public void setRpBillId(Long rpBillId) {
		this.rpBillId = rpBillId;
	}

	/**
	 * 单据编码
	 * @return
	 */
	public String getRpBillCode() {
		return rpBillCode;
	}

	public void setRpBillCode(String rpBillCode) {
		this.rpBillCode = rpBillCode;
	}

	/**
	 * 单据类型
	 * 收款单1、预收单2、退款单3
	 * 付款单-1、预付单-2、退款单-3
	 * @return
	 */
	public Integer getRpBillType() {
		return rpBillType;
	}

	public void setRpBillType(Integer rpBillType) {
		this.rpBillType = rpBillType;
	}

	/**
	 * 单据名称
	 * @return
	 */
	public String getRpBillName() {
		return rpBillName;
	}

	public void setRpBillName(String rpBillName) {
		this.rpBillName = rpBillName;
	}

	/**
	 * 单据日期
	 * @return
	 */
	public Date getBillDate() {
		return billDate;
	}

	public void setBillDate(Date billDate) {
		this.billDate = billDate;
	}

	/**
	 * 财务日期
	 * @return
	 */
	public Date getFuncDate() {
		return funcDate;
	}

	public void setFuncDate(Date funcDate) {
		this.funcDate = funcDate;
	}

	/**
	 * 借贷方向(1 : 收款; -1 : 付款)
	 * @return
	 */
	public Integer getDirect() {
		return direct;
	}

	public void setDirect(Integer direct) {
		this.direct = direct;
	}

	/**
	 * 客户ID
	 * @return
	 */
	public Integer getCustSuppId() {
		return custSuppId;
	}

	public void setCustSuppId(Integer custSuppId) {
		this.custSuppId = custSuppId;
	}

	/**
	 * 部门Id
	 * @return
	 */
	public Integer getDeptId() {
		return deptId;
	}

	public void setDeptId(Integer deptId) {
		this.deptId = deptId;
	}

	/**
	 * 职员(业务员)
	 * @return
	 */
	public Integer getEmpId() {
		return empId;
	}

	public void setEmpId(Integer empId) {
		this.empId = empId;
	}

	/**
	 * 制单人
	 * @return
	 */
	public Integer getMakerId() {
		return makerId;
	}

	public void setMakerId(Integer makerId) {
		this.makerId = makerId;
	}

	/**
	 * 收款、付款金额
	 * @return
	 */
	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	/**
	 * 折扣金额
	 * @return
	 */
	public BigDecimal getDiscount() {
		return discount;
	}

	public void setDiscount(BigDecimal discount) {
		this.discount = discount;
	}

	/**
	 * 核销金额
	 * @return
	 */
	public BigDecimal getCheckAmount() {
		return checkAmount;
	}

	public void setCheckAmount(BigDecimal checkAmount) {
		this.checkAmount = checkAmount;
	}

	/**
	 * 核销状态
	 * @return
	 */
	public Integer getCheckStatus() {
		return checkStatus;
	}

	public void setCheckStatus(Integer checkStatus) {
		this.checkStatus = checkStatus;
	}

	/**
	 * 年份
	 * @return
	 */
	public Integer getFyear() {
		return fyear;
	}

	public void setFyear(Integer fyear) {
		this.fyear = fyear;
	}

	/**
	 * 期间
	 * @return
	 */
	public Integer getPeriod() {
		return period;
	}

	public void setPeriod(Integer period) {
		this.period = period;
	}

	/**
	 * 记账标志
	 * @return
	 */
	public Boolean getArchived() {
		return archived;
	}

	public void setArchived(Boolean archived) {
		this.archived = archived;
	}

	/**
	 * 备注
	 * @return
	 */
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	public BigDecimal getSettleAmount() {
		return this.amount.add(this.discount);
	}
	
	public void setSettleAmount(BigDecimal settleAmount) {
		
	}

	/* (non-Javadoc)
	 * @see com.thinkgsp.jxc.model.BaseModel#toString()
	 */
	@Override
	public String toString() {
		ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE);
		sb.append("rpBillId",this.rpBillId)
		  .append("rpBillType",this.rpBillType)
		  .append("rpBillName",this.rpBillName)
		  .append("amount",this.amount)
		  .append("discount",this.discount);
		
		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see com.thinkgsp.jxc.model.BaseModel#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}
		if(!(o instanceof RpBill)) {
			return false;
		}
		final RpBill bill = (RpBill)o;
		if(rpBillId != null) {
			return rpBillId.equals(bill.getRpBillId());
		} else {
			return bill.getRpBillId() == null;
		}
	}

	/* (non-Javadoc)
	 * @see com.thinkgsp.jxc.model.BaseModel#hashCode()
	 */
	@Override
	public int hashCode() {
		return (this.rpBillId != null ? this.rpBillId.hashCode() : 0);
	}

}
